#!/usr/bin/python

import os
from mininet.net import Mininet
from mininet.node import RemoteController, Controller, OVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import Intf

def test3topo():
    "SingleSwitch with 3 hosts "

    info( "*** Connect controllers\n" )
    c0 = RemoteController( 'c0', ip='192.168.3.139', port=6653 )
    net = Mininet( controller=c0, switch=OVSSwitch )

    info( "*** Add switches\n" )
    s1 = net.addSwitch( 's1' )

    info( "*** Add hosts\n" )
    h1 = net.addHost( 'h1', ip = '192.168.3.12', mac = '00:00:00:00:00:01' )
    h2 = net.addHost( 'h2', ip = '192.168.3.13', mac = '00:00:00:00:00:02' )
    h3 = net.addHost( 'server', ip = '192.168.3.14', mac = '00:00:00:00:00:03' )

    info( "*** Add links\n" )
    net.addLink( s1, h1 )
    net.addLink( s1, h2 )
    net.addLink( s1, h3 )
   
    info( "*** Add Intf(default eth0)\n" )
    Intf( 'eth1', node=s1 )

    info( "*** Starting network\n" )
    net.build()
    c0.start()
    s1.start( [ c0 ] )

    CLI( net )

    info( "*** Stopping network\n" )
    net.stop()

if __name__ == '__main__':
    setLogLevel( 'info' )  # for CLI output
    test3topo()
